<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8"/>
    <title>个人信息</title>
    <link rel="stylesheet" type="text/css" href="css/public.css"/>
    <link rel="stylesheet" type="text/css" href="css/mygxin.css"/>
    <script src="js/jquery-1.12.4.min.js"></script>
    <script src="X-admin/lib/layui/layui.js"></script>
    <script src="X-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="X-admin/css/xadmin.css">
    <link rel="stylesheet" href="X-admin/lib/layui/css/layui.css">
    <script src="js/province.js"></script>
    <script src="js/data.js"></script>
</head>
<body>
<div class="layui-row">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>折扣</label>
            <div class="layui-input-inline">
                <input type="text" id="reduce" name="reduce" required="" autocomplete="off" class="layui-input">
            </div>
        </div>
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">-->
<!--                <span class="x-red">*</span>活动信息</label>-->
<!--            <div class="layui-input-inline">-->
<!--                <input type="text" id="prices" name="prices" required="" autocomplete="off" class="layui-input">-->
<!--            </div>-->
<!--        </div>-->
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><span class="x-red">*</span>活动信息</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" id="remark" name="remark" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label"><span class="x-red">*</span>开始时间</label>
            <div class="layui-input-inline">
                <input type="text" name="starts" id="starts" lay-verify="starts" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label"><span class="x-red">*</span>结束时间</label>
            <div class="layui-input-inline">
                <input type="text" name="endtim" id="endtim" lay-verify="endtim" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>状态</label>
            <div class="layui-input-block">
                <label>
                    <input type="radio" name="enable" value="1" title="开启" checked="">
                </label>
                <label>
                    <input type="radio" name="enable" value="0" title="关闭">
                </label>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>活动分类</label>
            <div class="layui-input-block">
                <label>
                    <input type="radio" name="aclass" value="1" title="商家活动" checked="">
                </label>
                <label>
                    <input type="radio" name="aclass" value="0" title="平台活动">
                </label>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button class="layui-btn" lay-filter="add" lay-submit="submit">提交修改</button>
        </div>
    </form>

</div>
</body>

<script>
    var Address_Prefix = "http://localhost:9200/api-lessors";
    $(function () {
        start();
    });

    function start() {
        layui.use(['form', 'upload','laydate'], function () {
            var form = layui.form;
            var upload = layui.upload;
            var laydate=layui.laydate;
            var laydate2=layui.laydate;
            //日期
            laydate.render({
                elem: '#starts'
            });
            laydate.render({
                elem: '#endtim'
            });
            var data=getActivityData();
            console.log(data,"当前活动数据");
            $("#reduce").val(data.reduce);
            $("#remark").val(data.remark);
            $("#starts").val(data.starts);
            $("#endtim").val(data.endtim);
            $("input[name=enable][value="+data.enable+"]").attr("checked",true);
            $("input[name=aclass][value="+data.enable+"]").attr("checked",true);
            form.render();
            form.on('submit(add)'
                , function (data) {
                    data = data.field;
                    data.actiid = sessionStorage.getItem("actiid");
                    // data.bussid = sessionStorage.getItem("busiid");
                    console.log(data);
                    $.ajax({
                        url: Address_Prefix + '/activity2/data/update',//地址：访问后台的地址
                        data: data,//前端传递给后台的数据
                        type: 'post',
                        async: false,
                        dataType: 'json',//是后端传递到前端的数据格式
                        success: function (data) {//后端给前端的一个反馈
                            console.log(data);
                            if (data.code === 0) {
                                layer.msg("ok！",{time:1000},function () {
                                    xadmin.close();
                                    xadmin.father_reload();
                                })
                            }else {
                                layer.msg("Not ok！",{time:1000})
                            }
                        }
                    });
                    return false;
                });

        })
        ;
    }

    //获取当前行活动数据
    function getActivityData() {
        var result = [];
        $.ajax({
            url: Address_Prefix + "/activity2/data/findById",
            data: {actiid:sessionStorage.getItem("actiid")},
            type: 'get',
            dataType: 'json',
            async : false,
            success: function (data) {
                console.log("当前活动数据",data.data);
                result = data.data;
                return result;
            }
        });
        return result;
    }


</script>
</html>
